using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace WebDauGia.Domain.Models.Mapping
{
    public class NhanVienMap : EntityTypeConfiguration<NhanVien>
    {
        public NhanVienMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.hoten)
                .IsRequired();

            this.Property(t => t.username)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.password)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.email)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.sodt)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.diachi)
                .IsRequired();

            this.Property(t => t.cmnd)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("NhanViens");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.hoten).HasColumnName("hoten");
            this.Property(t => t.username).HasColumnName("username");
            this.Property(t => t.password).HasColumnName("password");
            this.Property(t => t.email).HasColumnName("email");
            this.Property(t => t.sodt).HasColumnName("sodt");
            this.Property(t => t.diachi).HasColumnName("diachi");
            this.Property(t => t.cmnd).HasColumnName("cmnd");
            this.Property(t => t.idquyen).HasColumnName("idquyen");
            this.Property(t => t.idchucvu).HasColumnName("idchucvu");
            this.Property(t => t.ngaysinh).HasColumnName("ngaysinh");
            this.Property(t => t.active).HasColumnName("active");

            // Relationships
            this.HasOptional(t => t.ChucVu)
                .WithMany(t => t.NhanViens)
                .HasForeignKey(d => d.idchucvu);
            this.HasOptional(t => t.PhanQuyen)
                .WithMany(t => t.NhanViens)
                .HasForeignKey(d => d.idquyen);

        }
    }
}
